import net.minecraft.server.v1_16_R3.NBTTagCompound;
import net.minecraft.server.v1_16_R3.NBTTagString;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;
import java.util.Map;

public class Nms {
    public static ItemStack item(Map map) {
        String type = map.containsKey("Type") ? ((String) map.get("Type")) : "glass_pane";
        net.minecraft.server.v1_16_R3.ItemStack nms = CraftItemStack.asNMSCopy(new ItemStack(Material.matchMaterial(type)));
        NBTTagCompound cpd = (nms.hasTag()) ? nms.getTag() : new NBTTagCompound();
        if (map.containsKey("Tag"))
            cpd.set("Tag", NBTTagString.a((String) map.get("Tag")));
        if (map.containsKey("Left"))
            cpd.set("Left", NBTTagString.a((String) map.get("Left")));
        if (map.containsKey("Right"))
            cpd.set("Right", NBTTagString.a((String) map.get("Right")));
        if (map.containsKey("LeftS"))
            cpd.set("LeftS", NBTTagString.a((String) map.get("LeftS")));
        if (map.containsKey("RightS"))
            cpd.set("RightS", NBTTagString.a((String) map.get("RightS")));
        if (map.containsKey("Factor"))
            cpd.set("Factor", NBTTagString.a((String) map.get("Factor")));
        if (map.containsKey("Reward"))
            cpd.set("Reward", NBTTagString.a((String) map.get("Reward")));
        nms.setTag(cpd);
        ItemStack is = CraftItemStack.asBukkitCopy(nms);
        ItemMeta im = is.getItemMeta();
        if (map.containsKey("Name"))
            im.setDisplayName((String) map.get("Name"));
        else
            im.setDisplayName(" ");
        if (map.containsKey("Lore"))
            im.setLore((List<String>) map.get("Lore"));
        is.setItemMeta(im);
        return is;
    }

    public static String getEntityName(String entity) {
        switch (entity) {
            case "DROWNED":
                return "溺尸";
            case "GUARDIAN":
                return "守卫者";
            case "ELDER_GUARDIAN":
                return "远古守卫者";
            case "ZOMBIE":
                return "僵尸";
            case "HUSK":
                return "尸壳";
            case "ZOMBIE_VILLAGER":
                return "僵尸村民";
            case "SPIDER":
                return "蜘蛛";
            case "CAVE_SPIDER":
                return "洞穴蜘蛛";
            case "SKELETON":
                return "骷髅";
            case "STRAY":
                return "流浪者";
            case "CREEPER":
                return "苦力怕";
            case "SLIME":
                return "史莱姆";
            case "SILVERFISH":
                return "蠹虫";
            case "PHANTOM":
                return "幻翼";
            case "WITCH":
                return "女巫";
            case "PILLAGER":
                return "掠夺者";
            case "RAVAGER":
                return "劫掠兽";
            case "VEX":
                return "恼鬼";
            case "VINDICATOR":
                return "卫道士";
            case "HOGLIN":
                return "疣猪兽";
            case "ZOGLIN":
                return "僵尸疣猪兽";
            case "PIGLIN":
                return "猪灵";
            case "BLAZE":
                return "烈焰人";
            case "MAGMA_CUBE":
                return "岩浆怪";
            case "GHAST":
                return "恶魂";
            case "WITHER":
                return "凋零";
            case "ZOMBIFIED_PIGLIN":
                return "僵尸猪灵";
            case "PIGLIN_BRUTE":
                return "猪灵蛮兵";
            case "WITHER_SKELETON":
                return "凋零骷髅";
            case "ENDERMAN":
                return "末影人";
            case "ENDERMITE":
                return "末影螨";
            case "SHULKER":
                return "潜影贝";
            case "ENDER_DRAGON":
                return "末影龙";
            case "VILLAGER":
                return "村民";
            case "WANDERING_TRADER":
                return "游商";
            case "IRON_GOLEM":
                return "铁傀儡";
            case "SNOWMAN":
                return "雪傀儡";
            case "SHEEP":
                return "羊";
            case "COW":
                return "牛";
            case "CHICKEN":
                return "鸡";
            case "PIG":
                return "猪";
            case "RABBIT":
                return "兔子";
            case "HORSE":
                return "马";
            case "DONKEY":
                return "驴";
            case "MULE":
                return "骡";
            case "SKELETON_HORSE":
                return "骷髅马";
            case "WOLF":
                return "狼";
            case "CAT":
                return "猫";
            case "OCELOT":
                return "豹猫";
            case "PARROT":
                return "鹦鹉";
            case "FOX":
                return "狐狸";
            case "LLAMA":
                return "羊驼";
            case "PANDA":
                return "熊猫";
            case "POLAR_BEAR":
                return "北极熊";
            case "MUSHROOM_COW":
                return "哞菇";
            case "BAT":
                return "蝙蝠";
            case "BEE":
                return "蜜蜂";
            case "COD":
                return "鳕鱼";
            case "SALMON":
                return "鲑鱼";
            case "PUFFERFISH":
                return "河豚";
            case "TROPICAL_FISH":
                return "热带鱼";
            case "SQUID":
                return "鱿鱼";
            case "DOLPHIN":
                return "海豚";
            case "TURTLE":
                return "海龟";
            case "STRIDER":
                return "炽足兽";
            case "PRIMED_TNT":
                return "TNT";
            case "ENDER_CRYSTAL":
                return "末影水晶";
            case "DISPENSER":
                return "发射器";
            default:
                return entity;
        }
    }
}
